<?php

namespace App\Transformers\User;

use App\Models\UserRecharge;
use League\Fractal\TransformerAbstract;

class UserRechargesTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['user'];
    public function transform(UserRecharge $data)
    {
        return [
            'id' => $data->id,
            'user_id'=>$data->user_id ?? '',
            'order_number'=>$data->order_number ?? '',
            'price'=>$data->price ?? '',
            'give_price'=>$data->give_price ?? '',
            'recharge_type'=>$data->recharge_type ?? '',
            'recharge_typec'=>$data->rechargeTypeEnum[$data->recharge_type] ?? '',
            'is_paid'=>$data->is_paid ?? 1,
            'refund_price'=>$data->refund_price ?? '',
            'channel_type'=>$data->channel_type ?? '',
            'pay_time'=>$data->pay_time ?? '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    /**
     * 包含用户信息
     */

    public function includeUser(UserRecharge $userRecharge)
    {
        return $this->item($userRecharge->user, new UserTransformer());
    }
}
